package bookez.model.dao.hibernate;

import java.util.List;

import org.hibernate.Query;

import bookez.model.businessobject.TripSchedule;
import bookez.model.dao.TripScheduleDao;
import bookez.model.dao.generic.GenericDaoHibernateImpl;
import bookez.model.exception.DataAccessLayerException;

public class TripScheduleDaoHibernateImpl extends GenericDaoHibernateImpl<TripSchedule, Long> implements TripScheduleDao{

	public TripScheduleDaoHibernateImpl(Class<TripSchedule> type) {
		super(type);
		// TODO Auto-generated constructor stub
	}//end constructor

	@SuppressWarnings("unchecked")
	@Override
	public List<TripSchedule> findAll() throws DataAccessLayerException {
		// TODO Auto-generated method stub
		List<TripSchedule> result = null;
		
		try {
			Query query = getSession().getNamedQuery( TripSchedule.NamedQueries.FIND_ALL );
			result = query.list();
		}//end try
		
		catch ( Exception ex ) {
			throw new DataAccessLayerException( ex );
		}//end catch
		
		return result;
	}//end method findAll

	@Override
	public TripSchedule findByTripCode(String tripCode)
			throws DataAccessLayerException {
		TripSchedule result = null;
		
		try {
			Query query = getSession().getNamedQuery( TripSchedule.NamedQueries.FIND_BY_TRIP_CODE );
			query.setParameter( "tripCode", tripCode );
			result = (TripSchedule) query.uniqueResult();
			return result;
		}//end try
		
		catch ( Exception ex ) {
			throw new DataAccessLayerException( ex );
		}//end catch
		
	}//end method findByTripCode
	
	

}//end class TripScheduleDaoHibernateImpl
